return xsd_errors[i].errnum;
}
+/* Adds extra nul terminator, because we generally (always?) hold strings. */
static void *read_reply(int fd, enum xsd_sockmsg_type *type, unsigned int *len)
{
struct xsd_sockmsg msg;
if (!read_all(fd, &msg, sizeof(msg)))
return NULL;
- ret = malloc(msg.len);
+ ret = malloc(msg.len + 1);
if (!ret)
return NULL;
*type = msg.type;
if (len)
*len = msg.len;
+ ((char *)ret)[msg.len] = '\0';
return ret;
}
return ret;
}
-/* Get the value of a single file.
+/* Get the value of a single file, nul terminated.
* Returns a malloced value: call free() on it after use.
- * len indicates length in bytes.
+ * len indicates length in bytes, not including the nul.
*/
void *xs_read(struct xs_handle *h, const char *path, unsigned int *len)
{
*/
char **xs_directory(struct xs_handle *h, const char *path, unsigned int *num);
-/* Get the value of a single file.
+/* Get the value of a single file, nul terminated.
* Returns a malloced value: call free() on it after use.
- * len indicates length in bytes.
+ * len indicates length in bytes, not including the nul.
*/
void *xs_read(struct xs_handle *h, const char *path, unsigned int *len);
if (!value)
failed(handle);
+ /* It's supposed to nul terminate for us. */
+ assert(value[len] == '\0');
if (handle)
printf("%i:%.*s\n", handle, len, value);
else
else
barf("write flags 'none', 'create' or 'excl' only");
- if (!xs_write(handles[handle], path, data, strlen(data)+1, f))
+ if (!xs_write(handles[handle], path, data, strlen(data), f))
failed(handle);
}